package com.sentiment.database.bean;

import java.util.Date;
import java.util.List;

import org.bson.Document;
import org.bson.types.ObjectId;
import org.json.JSONObject;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sentiment.database.dbUtil.DbUtil;
import com.sentiment.nlpalgo.bean.Keywords;

public class CrawlInfo   {

	public static final String dbName = "SentimentDB";
	public static final String collection = "CrawInfo";

	private ObjectId _id;
	// 爬取时间（可比）
	private Date date;
	// 引用关键词，暂时没有
	private String keyword_id;
	// 分类属性（微博、新闻、论坛等）
	private String type;
	// 标题，如果是微博的话此处是话题，即搜索的关键字和与该关键字相关的内容
	private String title;
	// 正文
	private List<String> text;
	// 地址，微博url为用户的个人url
	private String url;
	// 发布媒体，微博此处为发布人的name字段
	private String publisher;
	// 发布时间（可比）
	private Date releaseTime;
	// 转载次数（可比）
	private Integer reprint;
	// 访问量（可比）
	private Integer pageView;
	// 评论量
	private Integer comment;
	// 舆情导向分析（可比）
	private Double sentiment;
	// 关键词分析
	private List<String> innerKeyword;

	public CrawlInfo() {

	}

	public CrawlInfo(Document doc) {
		super();
		_id = doc.getObjectId("_id");
		keyword_id = doc.getString("keyword_id");
		date = doc.getDate("date");
		type = doc.getString("type");
		title = doc.getString("title");
		text = (List<String>) doc.get("text");
		url = doc.getString("url");
		publisher = doc.getString("publisher");
		releaseTime = doc.getDate("releaseTime");
		reprint = doc.getInteger("reprint");
		pageView = doc.getInteger("pageView");
		comment = doc.getInteger("comment");
		sentiment = doc.getDouble("sentiment");
		innerKeyword = (List<String>) doc.get("innerKeyword");
	}

	public CrawlInfo(Document doc, int small) {
		_id = doc.getObjectId("_id");
		publisher = doc.getString("publisher");
		text = (List<String>) doc.get("text");
	}

	public List<String> getInnerKeyword() {
		return innerKeyword;
	}

	public void setInnerKeyword(List<String> innerKeyword) {
		this.innerKeyword = innerKeyword;
	}

	public CrawlInfo(Date date, String keyword_id, String type, String title, List<String> text, String url,
			String publisher, Date releaseTime, Integer reprint, Integer pageView, Integer comment, Double sentiment) {
		super();
		this.date = date;
		this.keyword_id = keyword_id;
		this.type = type;
		this.title = title;
		this.text = text;
		this.url = url;
		this.publisher = publisher;
		this.releaseTime = releaseTime;
		this.reprint = reprint;
		this.pageView = pageView;
		this.sentiment = sentiment;
		this.comment = comment;
	}

	public Document toDocument() {
		return new Document("date", date).append("keyword_id", keyword_id).append("type", type).append("title", title)
				.append("text", text).append("url", url).append("publisher", publisher)
				.append("releaseTime", releaseTime).append("reprint", reprint).append("pageView", pageView)
				.append("sentiment", sentiment).append("comment", comment).append("innerKeyword", innerKeyword);
	}
	public Document toDocument_id() {
		return new Document("_id", _id).append("date", date).append("keyword_id", keyword_id).append("type", type).append("title", title)
				.append("text", text).append("url", url).append("publisher", publisher)
				.append("releaseTime", releaseTime).append("reprint", reprint).append("pageView", pageView)
				.append("sentiment", sentiment).append("comment", comment).append("innerKeyword", innerKeyword);
	}

	public String get_id() {
		if (_id != null)
			return _id.toString();
		return null;
	}

	public void set_id(String _id) {
		this._id = new ObjectId(_id);
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getKeyword_id() {
		return keyword_id;
	}

	public void setKeyword_id(String keyword_id) {
		this.keyword_id = keyword_id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	public String toString() {
		return "CrawlInfo [_id=" + _id + ", date=" + date + ", keyword_id=" + keyword_id + ", type=" + type + ", title="
				+ title + ", text=" + text + ", url=" + url + ", publisher=" + publisher + ", releaseTime="
				+ releaseTime + ", reprint=" + reprint + ", pageView=" + pageView + ", comment=" + comment
				+ ", sentiment=" + sentiment + ", innerKeyword=" + innerKeyword + "]";
	}

	public Integer getComment() {
		return comment;
	}

	public void setComment(Integer comment) {
		this.comment = comment;
	}

	// public String getText2String() {
	// StringBuilder sb = new StringBuilder();
	// for(String s : text){
	// sb.append(s);
	// }
	// return sb.toString();
	// }

	public List<String> getText() {
		return text;
	}

	public void setText(List<String> text) {
		this.text = text;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}

	public Date getReleaseTime() {
		return releaseTime;
	}

	public void setReleaseTime(Date releaseTime) {
		this.releaseTime = releaseTime;
	}

	public Integer getReprint() {
		return reprint;
	}

	public void setReprint(Integer reprint) {
		this.reprint = reprint;
	}

	public Integer getPageView() {
		return pageView;
	}

	public void setPageView(Integer pageView) {
		this.pageView = pageView;
	}

	public Double getSentiment() {
		return sentiment;
	}

	public void setSentiment(Double sentiment) {
		this.sentiment = sentiment;
	}

	public JSONObject toJSONObject() {
		JSONObject json = new JSONObject();
		json.put("sentiment", sentiment);
		json.put("title", title);
		json.put("url", url);
		json.put("publisher", publisher);
		json.put("date", date);
		json.put("reprint", reprint);
		return json;
	}

	public static void main(String[] args) {
		DbUtil dbu = new DbUtil();
		dbu.openConnection(CrawlInfo.dbName, CrawlInfo.collection);
		CrawlInfo ci = new CrawlInfo();
		ci.setTitle("发改委上调成品油价格 90号汽油每升涨4分");
		Document d = dbu.query(ci.toDocument(), new String[] { "title" });
		ci = new CrawlInfo(d);
		dbu.closeConnection();
	}

}
